package com.i3q360.layui.modular.system.web;


import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.i3q360.layui.core.shiro.ShiroDbRealm;
import com.i3q360.layui.core.shiro.ShiroKit;
import com.i3q360.layui.modular.system.entity.UserInfo;
import com.i3q360.layui.modular.system.service.UserInfoService;

@Controller
@RequestMapping("/userInfo")
public class UserInfoController {

	@Autowired
	UserInfoService userInfoService;
	@Autowired
	ShiroDbRealm shiroDbRealm;
	
	
	@ModelAttribute
	public UserInfo info(Integer id){
		UserInfo user = null;
		if(id!=null){
			user = userInfoService.queryById(id);
		}
		return user;
	}
	
    /**
     * 用户查询.
     * @return
     */
    @RequestMapping("/userList")
    @RequiresPermissions("userInfo:view")//权限管理;
    public String userInfo(){
        return "userInfo.html";
    }

    /**
     * 用户添加;
     * @return
     */
    @RequestMapping("/userAdd")
    @RequiresPermissions("userInfo:add")//权限管理;
    public String userInfoAdd(){
        return "userInfoAdd.html";
    }

    /**
     * 用户删除;
     * @return
     */
    @RequestMapping("/userDel")
    @RequiresPermissions("userInfo:del")//权限管理;
    public String userDel(){
        return "userInfoDel.html";
    }
    
    /**
     * 修改用戶信息
     */
    @RequestMapping("/edit")
    @ResponseBody
    public boolean edit(UserInfo user){
    	
    	userInfoService.save(user);
    	
//    	shiroDbRealm.getAuthenticationCache().remove(ShiroKit.getSubject().getPrincipals());
//    	ShiroKit.getSubject().releaseRunAs();
    	return true;
    }
    
    
    
}